// components/get_cash/get_cash.js
Component({
	/**
	 * 组件的属性列表
	 */
	properties: {
		money:String
	},

	/**
	 * 组件的初始数据
	 */
	data: {
		show_form_box: false,
		pay_list: [{
				title: '提现至支付宝',
				icon: 'http://img.gek6.com/FtIh6-F2cJwDQGz0dJt0SHD1Whi5',
				type: '3'
			},
			{
				title: '提现至微信',
				icon: 'http://img.gek6.com/FpD0pI3P83ICbXsdFnQTJ4_JW0bt',
				type: '1'
			},
			{
				title: '提现至银行卡',
				icon: 'http://img.gek6.com/FmTsU1viupfntrhZ7NJoTPpzPP4L',
				type: '2'
			},
		],
		animate:'',
		get_cash_type:'',
		show_loading:false
	},

	/**
	 * 组件的方法列表
	 */
	methods: {
		to_cash_next(e) {
			let index = e.currentTarget.dataset.index;
			console.log(index);
			
			if (index == 0) {
				this.setData({
					get_cash_type:index
				})
				this.switch_form_box()
			};
			if (index == 1) {
				let that = this;
				this.setData({
					get_cash_type:index
				})
				wx.showModal({
					title:"温馨提示",
					content:"确认提现到微信吗",
					success(e){
						if(e.confirm){
							that._submit()
						}
					}
				})
			};
			if (index == 2) {
				this.setData({
					get_cash_type:index
				})
				this.switch_form_box()
			}
		},
		switch_form_box() {
			let animate = wx.createAnimation({
				timingFunction: 'ease-in',
				duration: 200
			})
			if (this.data.show_form_box) {
				// 关闭
				this.setData({
					show_loading:false
				})
				animate.opacity(0).translateY(30).step();
				this.setData({
					animate: animate.export()
				})
				setTimeout(() => {
					this.setData({
						show_form_box: false
					})
				}, 200)

			} else {
				// 打开
				this.setData({
					show_form_box: true
				});

				setTimeout(() => {
					animate.opacity(1).translateY(0).step();
					this.setData({
						animate: animate.export()
					})
				}, 80);
			}
		},
		_submit(e){
			
			console.log(this.data.get_cash_type);
			let item = this.data.pay_list[this.data.get_cash_type];
			console.log(item);
			let data = {};
			
			if(item.type==1){
				// 微信
			}
			if(item.type==2){
				// 银行卡
				data = e.detail.value
				if(!data.card_no){
					wx.showToast({
						title:"请输入银行卡号",
						icon:"none"
					})
				}
				if(!data.real_name){
					wx.showToast({
						title:"请输入真实姓名",
						icon:"none"
					})
				}
				
			}
			if(item.type==3){
				// 支付宝
				data = e.detail.value
				if(!data.alipay){
					wx.showToast({
						title:"请输入支付宝账号",
						icon:"none"
					})
				}
				if(!data.real_name){
					wx.showToast({
						title:"请输入真实姓名",
						icon:"none"
					})
				}
			}
			
			data.type = item.type;
			data.money = this.data.money;
			this.setData({
				show_loading:true
			})
			console.log(data);
			this.triggerEvent('cashsubmit', data, {})
		}
	}
})
